package com.ibeeking.found.msg.rest.controller.v1;

import com.ibeeking.found.common.annotation.LoginUser;
import com.ibeeking.found.common.entity.CurrentUser;
import com.ibeeking.found.common.enums.PublishStatusEnum;
import com.ibeeking.found.msg.rest.service.ISmsConfigService;
import com.ibeeking.found.msg.service.common.param.SmsConfigParam;
import com.ibeeking.found.msg.service.common.query.SmsConfigQuery;
import com.ibeeking.found.msg.service.common.vo.SmsConfigVO;
import com.ibeeking.nematos.constants.enums.LogSourceEnum;
import com.ibeeking.nematos.constants.enums.OperateLogTypeEnum;
import com.ibeeking.nematos.log.annotation.Log;
import com.ibeeking.nematos.utils.base.BaseValidationGroup;
import com.ibeeking.nematos.utils.bean.BeanUtil;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName SmsConfigController控制器
 * @Description
 * @Author ibeeking
 * @Date 2020-12-09 10:54
 **/
@RestController
@RequestMapping("/msg/smsConfig/v1")
public class SmsConfigController {

    @Resource
    private ISmsConfigService smsConfigServiceImpl;

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "消息配置分页查询")
    @PostMapping(value = "/listSmsConfig")
    public List<SmsConfigVO> listSmsConfig() {
        return smsConfigServiceImpl.listAll();
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "消息配置列表")
    @PostMapping(value = "/effectiveList")
    public List<SmsConfigVO> effectiveList(@RequestBody SmsConfigQuery query) {
        SmsConfigQuery smsConfigQuery = BeanUtil.convertBean(query, SmsConfigQuery.class);
        smsConfigQuery.setPublishStatus(PublishStatusEnum.ENABLE.getValue());
        return smsConfigServiceImpl.list(smsConfigQuery);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "消息配置修改")
    @PostMapping(value = "/modify")
    public Boolean modify(@RequestBody SmsConfigParam param) {
        return smsConfigServiceImpl.modify(param);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.QUERY, describe = "消息配置查看")
    @GetMapping(value = "/view/{id}")
    public SmsConfigVO view(@PathVariable("id") Long id) {
        return smsConfigServiceImpl.view(id);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "消息配置启用/禁用")
    @PostMapping(value = "/changePublishStatus/{id}/{status}")
    public Boolean changePublishStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return smsConfigServiceImpl.changePublishStatus(id, status);
    }

    @Log(logSource = LogSourceEnum.TENANT_LOG,logType = OperateLogTypeEnum.MODIFY, describe = "消息配置启用/禁用")
    @PostMapping(value = "/changeDefaultStatus/{id}/{status}")
    public Boolean changeDefaultStatus(@PathVariable("id") Long id, @PathVariable("status") Integer status) {
        return smsConfigServiceImpl.changeDefaultStatus(id, status);
    }

}
